package com.briup.ch11;

import java.io.*;

/**
 * @Author briup-adam
 * @Date 2023/10/19 上午11:29
 * @Description
 **/

public class CompareReadAndWriteTime {
    static void  nodeStream(){
        long start = System.currentTimeMillis();
        //声明
        FileInputStream fis=null;
        FileOutputStream fos=null;

        try {
            fis=new FileInputStream("02code/src/背影Dest.txt");
            fos=new FileOutputStream("02code/src/背影dest1.txt");
            byte [] b=new byte[8];
            int len=0;
            while((len=fis.read(b))!=-1){
                fos.write(b,0,len);
            }
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (fis!=null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos!=null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
    static  void bufferStream(){
        long start = System.currentTimeMillis();
        FileInputStream fis=null;
        FileOutputStream fos=null;
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;

        try {
            fis=new FileInputStream("02code/src/背影Dest.txt");
            fos=new FileOutputStream("02code/src/背影dest1.txt");
            bis=new BufferedInputStream(fis);
            bos=new BufferedOutputStream(fos);

            byte []b =new byte[8];
            int len=0;
            while ((len=bis.read(b))!=-1){
                bos.write(b,0,len);
            }
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
           try {
               if (bis!=null)
                   bis.close();
               if (bos!=null)
                   bos.close();
               if (fis!=null)
                   fis.close();
               if (fos!=null)
                   fos.close();
           }catch (Exception e){
               e.printStackTrace();
           }
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }

    public static void main(String[] args) {
        nodeStream();
        bufferStream();
    }
}
